package com.azkj.album.adapter;

import static com.azkj.album.view.fragment.gallery.GalleryChildFragment.GALLERY_MINE;
import static com.azkj.album.view.fragment.gallery.GalleryChildFragment.GALLERY_SYS;

import android.widget.ImageView;

import com.azkj.album.R;
import com.azkj.album.dto.GalleryBean;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

public class GalleryAdapterSelect extends BaseQuickAdapter<GalleryBean, BaseViewHolder> {

    private String GALLERY_TYPE = GALLERY_SYS;

    public GalleryAdapterSelect(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, GalleryBean item) {
        helper.addOnClickListener(R.id.iv_download).addOnClickListener(R.id.iv_collect).addOnClickListener(R.id.iv_del)
                .addOnClickListener(R.id.iv_share).addOnClickListener(R.id.iv_image);
        helper.addOnLongClickListener(R.id.iv_download).addOnLongClickListener(R.id.iv_collect)
                .addOnLongClickListener(R.id.iv_del)
                .addOnLongClickListener(R.id.iv_share).addOnLongClickListener(R.id.iv_image);

        helper.setText(R.id.tv_name, item.getName());
        helper.setText(R.id.tv_uses, item.getUse_count() + "次使用");
        helper.setImageResource(R.id.iv_collect, !"0".equals(item.getIs_collect()) ? R.mipmap.ic_gallery_coll_y : R.mipmap.ic_gallery_coll_n);
        helper.setImageResource(R.id.iv_del, item.isSelect() ? R.mipmap.ic_new_photo_yes_select : R.mipmap.ic_new_photo_no_select);
        Glide.with(mContext)
                .load(item.getImage())
                .apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL))
                .into((ImageView) helper.getView(R.id.iv_image));
        helper.setGone(R.id.ll_bottom, !GALLERY_TYPE.equals(GALLERY_MINE));
    }

    public void setType(String type) {
        GALLERY_TYPE = type;
        this.notifyDataSetChanged();
    }
}
